﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OblivionLevelingHelper.Skills;

namespace OblivionLevelingHelper.Attributes
{
    public class Attribute
    {
        protected int BaseLevel = 30;
        public int Level = 0;
        public AttributeTypes AttributeType;
        private readonly Character _parent;
        private readonly Dictionary<SkillTypes, Skill> _governingSkills;

        public Attribute(AttributeTypes attributeType, Character parent)
        {
            _parent = parent;
            _governingSkills = new Dictionary<SkillTypes, Skill>();
            AttributeType = attributeType;
        }

        public int CalculateStat()
        {
            var score = BaseLevel + Level;
            score += _parent.Race.GetAttributeModifier(AttributeType);
            score += _parent.Birthsign.GetAttributeModifier(AttributeType);
            score += _parent.Class.HasFavoredAttribute(AttributeType) ? 5 : 0;
            return score;
        }

        public string GetName()
        {
            return AttributeType.ToString();
        }

        public void AddGoverningSkill(Skill skill)
        {
            skill.GovernedAttribute = this;
            _governingSkills.Add(skill.SkillType, skill);
        }

        public Skill GetGoverningSkill(SkillTypes skillType)
        {
            return _governingSkills.ContainsKey(skillType) ? _governingSkills[skillType] : null;
        }

        public List<Skill> GetGoverningSkills()
        {
            return _governingSkills.Values.ToList();
        }
    }
}
